< previous page page_413 next page >

Page 413
e10a6a0a59f035e870d90cca05b85fce.gif
        If Objects.Count > MAX_OBJECTS Then Divide
    End If
End Sub

' Place this object in the proper child(ren).
Private Sub PlaceObject(ByVal obj As Object)
Dim x1 As Single 
Dim x2 As Single 
Dim y1 As Single 
Dim y2 As Single 

    obj.Bound x1, y1, x2, y2 
    If y2 > ymid And x1 < xmid Then NWchild.Add obj
    If y2 > ymid And x2 > xmid Then NEchild.Add obj
    If y1 < ymid And x1 < xmid Then SWchild.Add obj
    If y1 < ymid And x2 > xmid Then SEchild.Add obj
End Sub

' Create the children and divide the object.
Private Sub Divide()
Dim obj As Object

    ' Create the children.
    Set NWchild = New QtreeNode
    NWchild.SetBounds xmin, xmid, ymid, ymax

    Set NEchild = New QtreeNode
    NEchild.SetBounds xmid, xmax, ymid, ymax

    Set SWchild = New QtreeNode
    SWchild.SetBounds xmin, xmid, ymin, ymid

    Set SEchild = New QtreeNode
    SEchild.SetBounds xmid, xmax, ymin, ymid

    ' Move the objects into the proper children.
    For Each obj In Objects
        PlaceObject obj
    Next obj

    ' Remove the Objects collection.
    Set Objects = Nothing
End Sub

' Set the bounds for this quadtree node. 
Public Sub SetBounds(ByVal x1 As Single, ByVal x2 As Single, _
    ByVal y1 As Single, ByVal y2 As Single)

    xmin = x1
    ymin = y1
    xmax = x2

 
< previous page page_413 next page >